home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib25 / mntlib25.zoo / _fixsfsi.cpp < prev    next >
Text File  |  1992-09-29  |  2KB  |  90 lines

  1. |
  2. |  single float to long conversion routine
  3. |
  4. | Andreas Schwab (schwab@ls5.informatik.uni-dortmund.de)
  5. |  mostly copied from _fixdfsi.cpp
  6. |  (error check removed because no checking possible)
  7.  
  8. #ifndef __M68881__
  9.  
  10.     .text
  11.     .even
  12.     .globl    ___fixsfsi
  13.  
  14. ___fixsfsi:
  15.  
  16. #ifdef sfp004
  17.  
  18. comm =     -6
  19. resp =    -16
  20. zahl =      0
  21.  
  22.     lea    0xfffffa50:w,a0
  23.     movew    #0x5403,a0@(comm)    | fintrz to fp0
  24.     cmpiw    #0x8900,a0@(resp)    | check
  25.     movel    a7@(4),a0@
  26.     movel    a7@(8),a0@
  27.     movew    #0x6000,a0@(comm)    | result to d0
  28. | waiting loop is NOT coded directly
  29. 1:    cmpiw    #0x8900,a0@(resp)
  30.     beq    1b
  31.     movel    a0@,d0
  32.         
  33. #else /* !sfp004 */
  34.  
  35. BIAS4    =    0x7F-1
  36.  
  37.     movel    sp@(4),d0    | get number
  38.     movel    d2,sp@-        | save register
  39.     movel    d0,d1
  40.     swap    d1        | extract exp
  41.     movew    d1,d2        | extract sign
  42.     lsrw    #7,d1
  43.     andw    #0xff,d1    | kill sign bit
  44.  
  45.     andl    #0x7fffff,d0    | remove exponent from mantissa
  46.     orl    #0x800000,d0    | restore implied leading "1"
  47.  
  48.     cmpw    #BIAS4,d1    | check exponent
  49.     blt    zero        | strictly factional, no integer part ?
  50.     cmpw    #BIAS4+32,d1    | is it too big to fit in a 32-bit integer ?
  51.     bgt    toobig
  52.  
  53.     subw    #BIAS4+24,d1    | adjust exponent
  54.     bgt    2f        | shift up
  55.     beq    7f        | no shift (never too big)
  56.  
  57. 1:    negw    d1
  58.     lsrl    d1,d0        | shift down to align radix point;
  59.                 | extra bits fall off the end (no rounding)
  60.     bra    7f        | never too big
  61.  
  62. 2:    lsll    d1,d0        | shift up to align radix point
  63.  
  64. 3:    cmpl    #0x80000000,d0    | -2147483648 is a nasty evil special case
  65.     bne    6f
  66.     tstw    d2        | this had better be -2^31 and not 2^31
  67.     bpl    toobig
  68.     bra    8f
  69. 6:    tstl    d0        | sign bit set ? (i.e. too big)
  70.     bmi    toobig
  71. 7:
  72.     tstw    d2        | is it negative ?
  73.     bpl    8f
  74.     negl    d0        | negate
  75. 8:
  76.     movel    sp@+,d2
  77.     rts
  78.  
  79. zero:
  80.     clrl    d0        | make the whole thing zero
  81.     bra    8b
  82.  
  83. toobig:
  84.     movel    #0x7fffffff,d0    | ugh. Should cause a trap here.
  85.     bra    8b
  86.  
  87. #endif /* !sfp004*/
  88.  
  89. #endif /* !__M68881__ */
  90.